package com.teamc.team.service.impl;

import com.teamc.team.entity.Type;
import com.teamc.team.mapper.TypeMapper;
import com.teamc.team.service.ITypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ding
 * @since 2021-06-10
 */
@Service
public class TypeServiceImpl extends ServiceImpl<TypeMapper, Type> implements ITypeService {

    @Autowired
    public TypeMapper mapper;

    @Override
    public String findTypeIdByName(String name) {
        List<Type> collect = mapper.selectList(null).stream()
                .filter(x -> x.getTypeName().equals(name))
                .collect(Collectors.toList());
        return collect.get(0).getTypeId();
    }

    @Override
    public List<String> findAllNames() {
        List<String> strings = new ArrayList<>();
        mapper.selectList(null).forEach(x -> strings.add(x.getTypeName()));
        return strings;
    }
}
